func spiralOrder(matrix [][]int) []int {
	maxRow, maxCol := len(matrix), len(matrix[0])
	if maxRow == 0 || maxCol == 0 {
		return []int{}
	}
	left, right, up, down := 0, maxCol-1, 0, maxRow-1
	mn := maxRow * maxCol
	x, y := 0, 0
	dirs := [4][2]int{{0, 1}, {1, 0}, {0, -1}, {-1, 0}}
	var res []int
	cur_d := 0
	for i := 0; i < mn; i++ {
		res = append(res, matrix[x][y])
		if cur_d == 0 && y == right {
			cur_d += 1
			up += 1
		} else if cur_d == 1 && x == down {
			cur_d += 1
			right -= 1
		} else if cur_d == 2 && y == left {
			cur_d += 1
			down -= 1
		} else if cur_d == 3 && x == up {
			cur_d += 1
			left += 1
		}
		cur_d %= 4
		x += dirs[cur_d][0]
		y += dirs[cur_d][1]
	}
	return res
}
